package com.yj.web.WeChat.Message;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import com.yj.web.util.XStreamCDataConverter;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yanlinyang on 2017/9/10.
 */
@XStreamAlias("xml")
public class WxXmlOutNewsMessage extends WxXmlOutMessage {
    private static final long serialVersionUID = -4604402850905714772L;

    @XStreamAlias("Articles")
    protected final List<Item> articles = new ArrayList<>();
    @XStreamAlias("ArticleCount")
    protected int articleCount;

    public WxXmlOutNewsMessage() {
        this.msgType = "news";
    }

    public int getArticleCount() {
        return this.articleCount;
    }

    public void addArticle(Item item) {
        this.articles.add(item);
        this.articleCount = this.articles.size();
    }

    public List<Item> getArticles() {
        return this.articles;
    }

    @Data
    @XStreamAlias("item")
    public static class Item implements Serializable {

        private static final long serialVersionUID = -4971456355028904754L;

        @XStreamAlias("Title")
        @XStreamConverter(value = XStreamCDataConverter.class)
        private String Title;

        @XStreamAlias("Description")
        @XStreamConverter(value = XStreamCDataConverter.class)
        private String Description;

        @XStreamAlias("PicUrl")
        @XStreamConverter(value = XStreamCDataConverter.class)
        private String PicUrl;

        @XStreamAlias("Url")
        @XStreamConverter(value = XStreamCDataConverter.class)
        private String Url;
    }
}
